<div class="col-md-4 col-md-offset-4">
  <%= form_for(@blog) do |f| %>
    <% if @blog.errors.any? %>
      <div id="error_explanation">
        <h2><%= "保存的时候出现了#{@blog.errors.count}个错误" %> </h2>

        <ul>
        <% @blog.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
        </ul>
      </div>
    <% end %>

    <div class="field">
      <%= f.label :title %><br>
      <%= f.text_field :title %>
    </div>
    <div class="field">
      <%= f.label :content %><br>
      <%= f.text_area :content %>
    </div>
    <div class="field">
      <%= f.label :time %><br>
      <%= f.datetime_select :time %>
    </div>
      <div class="field">
      <%= f.label :visible %><br>
      <%= f.check_box :visible %>
    </div>
    <div class="field">
      <%= f.label :category %><br>
      <%= f.collection_select( :categories, Category.all, :id, :name) %>
    </div>

        <div class="field">
      <%= f.label :category %><br>
      <%= f.collection_check_boxes( :category_ids, Category.all, :id, :name) do |b|%>
         <%= b.label(:"data-value" => b.value) { b.check_box + b.text } %>
      <% end %>
    </div>

    <div class="actions">
      <%= f.submit class: "btn btn-primary"%>
    </div>
  <% end %>
</div>